/**
 * @file main.cpp
 * @author luxian (you@domain.com)
 * @brief  这里是Winpcap 的实例代码 （已废弃）
 * @version 0.1
 * @date 2022-03-02
 * 
 * @copyright Copyright (c) 2022
 * 
 */
#include<iostream>
#include<cstdio>
#include<cstdlib>
// #include<stdio.h>
// #include<stdlib.h>
//#define u_int unsigned int
//#define u_short unsigned short
//#define u_char unsigned char

#define HAVE_REMOTE

#include "pcap.h"
#include "remote-ext.h"

#pragma comment(lib,"wpcap.lib")

// #include"winpcap/pcap.h"

typedef unsigned int u_int;
typedef unsigned short u_short;
typedef unsigned char u_char;


using namespace std;

int main()
{
	pcap_if_t *alldevs;
	pcap_if_t *d;
	int i = 0;
	char errbuf[PCAP_ERRBUF_SIZE];
	
	/* 获取本地机器设备列表 */
	if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
	{
		fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf);
		exit(1);
	}

	/* 打印列表 */
	for (d = alldevs; d != NULL; d = d->next)
	{
		printf("%d. %s", ++i, d->name);
		if (d->description)
			printf(" (%s)\n", d->description);
		else
			printf(" (No description available)\n");
	}

	if (i == 0)
	{
		printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
		return 1;
	}

	/* 不再需要设备列表了，释放它 */
	pcap_freealldevs(alldevs);
	getchar();
	return 0;
}
